package com.enlorenz.core.channel.socket.common.dstroute;

import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.enlorenz.core.channel.common.dstobj.IDstObjectManager;
import com.enlorenz.core.channel.common.dstobj.IDstRoute;
import com.enlorenz.core.channel.socket.common.dstroute.category.NioDstRoute;

public class NioObjectManager implements IDstObjectManager{
	private Map<SocketChannel,NioDstRoute> map=new HashMap<SocketChannel, NioDstRoute>();
	@Override
	public List<IDstRoute> getAllDstObjectList() {
		return new ArrayList(map.values());
	}

	@Override
	public List<IDstRoute> selectDstObjectListByCondition(Map condition) {
		String ip=(String)condition.get("ip");
		
		return null;
	}

	@Override
	public void addDstObject(IDstRoute dstObject) {
		NioDstRoute nco=(NioDstRoute)dstObject;
		SocketChannel socketChannel=(SocketChannel)nco.getConnSource();
		map.put(socketChannel, nco);
	}

	@Override
	public IDstRoute removeDstObject(IDstRoute dstObject) {
		NioDstRoute nco=(NioDstRoute)dstObject;
		SocketChannel socketChannel=(SocketChannel)nco.getConnSource();
		return map.remove(socketChannel);
	}

	@Override
	public List<IDstRoute> removeAllDstObject() {
		List rList=new ArrayList(map.values());
		map.clear();
		return rList;
	}

	@Override
	public int size() {
		return map.size();
	}

}
